package com.neuedu.servlet.business;


import com.google.gson.Gson;
import com.neuedu.pojo.Business;
import com.neuedu.pojo.PageResult;
import com.neuedu.service.BusinessService;
import com.neuedu.service.Imp.BusinessServiceImp;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/selectBus")
public class BusinessServlet extends HttpServlet {
    private BusinessService businessService = new BusinessServiceImp();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 规范浏览器携带数据的格式
        req.setCharacterEncoding("utf-8");


        String account = req.getParameter("account");
        String telephone = req.getParameter("telephone");
        String contact = req.getParameter("contact");
        String currentPage = req.getParameter("currentPage");
        String pageSize = req.getParameter("pageSize");

        PageResult<List<Business>> list = businessService.selectAll(account,telephone,contact,currentPage,pageSize);

        Gson gson = new Gson();
        String json = gson.toJson(list);

        resp.setContentType("application/json;charset=utf-8");
        resp.getWriter().write(json);

    }
}
